package com.llyb.lease.web.admin.Timer;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.llyb.lease.model.entity.LeaseAgreement;
import com.llyb.lease.model.enums.LeaseStatus;
import com.llyb.lease.web.admin.service.LeaseAgreementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.LinkedList;

@Component
public class LeaseAgreementTimer {

    @Autowired
    private LeaseAgreementService leaseAgreementService;

    @Scheduled(cron = "* * 3 * * *")
    public void timer(){
        LambdaUpdateWrapper<LeaseAgreement> objectLambdaUpdateWrapper = new LambdaUpdateWrapper<>();
        objectLambdaUpdateWrapper.in(LeaseAgreement::getStatus, LeaseStatus.SIGNED,LeaseStatus.WITHDRAWING,LeaseStatus.RENEWING);
        objectLambdaUpdateWrapper.set(LeaseAgreement::getStatus,LeaseStatus.EXPIRED);

        leaseAgreementService.update(objectLambdaUpdateWrapper);
    }
}
